package com.ladlee.parking.pay.v3.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.ladlee.parking.pay.v3.enums.PayType;
import com.ladlee.parking.pay.v3.handle.PayHandler;
import com.ladlee.parking.pay.v3.service.PayService;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class AliPayService implements PayService {

    /**
     * 该支付方式下的所有类型
     */
    List<PayHandler> handlers;

    @Override
    public boolean support(String payType) {
        return PayType.ALIPAY.getType().equals(payType);
    }

    @Override
    public PayHandler handler(String tradeType) {
        if (CollUtil.isNotEmpty(handlers)) {
            for (PayHandler handler : handlers) {
                if (handler.support(tradeType)) {
                    return handler;
                }
            }
        }
        return null;
    }
}
